#!/usr/bin/env bash

# odie@sdf

source '../say.sh'

chan="$2"
nick="$3"

if [[ -n "$nick" && ! "$nick" =~ [^[:alnum:]_-] && "${nick::1}" != '-' ]]; then
    read -ra seen <<< "$(grep "^$nick " '../../data/seen')"
    if [[ -z "$seen" ]]; then
        msg="The user $nick was not found."
    else
        msg="$nick was last seen on ${seen[@]:1:3} in ${seen[4]}."
    fi
else
    msg='Please use the following syntax: !seen <nickname>.'
fi

say "$chan" "$msg"

